using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Microblaze.Simulator.Components.Microblaze
{
  public class UnknownInstructionException 
    : Exception
  {
    private uint value;

    public UnknownInstructionException(uint value) : 
      base("Unknown instruction: " + value + "(" + getBinaryString(value) + ")")
    {
      this.value = value;
    }

    private static string getBinaryString(uint value)
    {
      StringBuilder str = new StringBuilder();

      int i = 31;
      for (; i > 31 - 6; i--)
        str.Append((value >> i) & 1);

      str.Append(" ");

      for (; i > 31 - 11; i--)
        str.Append((value >> i) & 1);

      str.Append(" ");

      for (; i > 31 - 16; i--)
        str.Append((value >> i) & 1);

      str.Append(" ");

      for (; i >= 31 - 21; i--)
        str.Append((value >> i) & 1);

      str.Append(" ");

      for (; i >= 0; i--)
        str.Append((value >> i) & 1);

      return str.ToString();
    }
  }
}
